//
//  CYYLoadView.m
//  LetsParty
//
//  Created by YG on 15/9/23.
//  Copyright (c) 2015年 LetsPartyTeam. All rights reserved.
//

#import "CYYLoadView.h"
#import "CYYCustomTextField.h"

@interface CYYLoadView ()

@property (nonatomic, strong) UIButton * loadButton;//登陆按钮
@property (nonatomic, strong) UIButton * forgetPasswordButton;//忘记密码按钮
@property (nonatomic, strong) CYYCustomTextField * mobilePhoneTextField;//手机号TextField
@property (nonatomic, strong) CYYCustomTextField * passwordTextField;//密码textField

- (void)initializeUserInterafce;

@end

@implementation CYYLoadView

#pragma mark - init
- (instancetype)init{
    if (self = [super init]) {
        [self initializeUserInterafce];
    }
    return self;
}

#pragma mark - private methods
- (void)initializeUserInterafce{
    [self addSubview:self.passwordTextField];
    [self addSubview:self.mobilePhoneTextField];
    [self addSubview:self.loadButton];
    [self addSubview:self.forgetPasswordButton];
}

- (CYYCustomTextField *)haveTextFieldWithFrame:(CGRect)frame title:(NSString *)string leftViewName:(NSString *)nameString{
    CYYCustomTextField * cTextField = [[CYYCustomTextField alloc]init];
    cTextField.frame = DHFlexibleFrame(frame, NO);
    cTextField.placeholder = string;
    cTextField.textAlignment = NSTextAlignmentLeft;
    cTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    cTextField.borderStyle = UITextBorderStyleRoundedRect;
    cTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    cTextField.borderStyle = UITextBorderStyleNone;
    cTextField.textColor = [UIColor whiteColor];
    [cTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    UIButton * cButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cButton.frame = DHFlexibleFrame(CGRectMake(0, 0, 20, 20), NO);
    [cButton setImage:[UIImage imageNamed:nameString] forState:UIControlStateNormal];
    cTextField.leftView = cButton;
    cTextField.leftViewMode = UITextFieldViewModeAlways;
    return cTextField;
}

#pragma mark - getter
- (UIButton *)loadButton{
    if (!_loadButton) {
        _loadButton = ({
            //设置登陆button
            UIButton *loadButton = [UIButton buttonWithType:UIButtonTypeCustom];
            loadButton.center = DHFlexibleCenter(CGPointMake(160, 160));
            loadButton.bounds = DHFlexibleFrame(CGRectMake(0, 0, 280, 40), NO);
            [loadButton setTitle:@"登陆" forState:UIControlStateNormal];
            [loadButton setTitleColor:COLOR_RGB(61, 142, 233, 1) forState:UIControlStateNormal];
            loadButton.layer.cornerRadius = 20 * DHFlexibleVerticalMutiplier();
            loadButton.backgroundColor = [UIColor whiteColor];
            loadButton.alpha = 0.8;
            loadButton;
        });
    }
    return _loadButton;
}

- (UIButton *)forgetPasswordButton{
    if (!_forgetPasswordButton) {
        _forgetPasswordButton = ({
            UIButton * cButton = [UIButton buttonWithType:UIButtonTypeCustom];
            cButton.frame = DHFlexibleFrame(CGRectMake(210, 100, 100, 40),NO);
            [cButton setTitle:@"忘记密码？" forState:UIControlStateNormal];
            cButton;
        });
    }
    return _forgetPasswordButton;
}

- (CYYCustomTextField *)mobilePhoneTextField{
    if (!_mobilePhoneTextField) {
        _mobilePhoneTextField = ({
            [self haveTextFieldWithFrame:CGRectMake(20, 10, 280, 40) title:@"LetsParty手机号" leftViewName:@"iconfont-shouji-1"];
        });
    }
    return _mobilePhoneTextField;
}

- (CYYCustomTextField *)passwordTextField{
    if (!_passwordTextField) {
        _passwordTextField = ({
            [self haveTextFieldWithFrame:CGRectMake(20, 60, 280, 40) title:@"LetsParty密码" leftViewName:@"iconfont-mima"];
        });
        _passwordTextField.secureTextEntry = YES;
    }
    return _passwordTextField;
}

@end
